
angular.module('app')
    .controller('forumAttentionPersonController', [ '$rootScope', '$scope', '$http', '$state','$timeout',
        function($rootScope, $scope, $http, $state, $timeout) {
            $scope.title = '关注前100用户统计';
            $scope.searchParams = {};
            $scope.loading = false;
            $scope.param={};
            $scope.search = function () {
                $scope.loading = true;
                $.ajax({
                    url : $scope.app.project_name+'/forumAttentionPerson/read/list',
                    data:$scope.param
                }).then(function(result) {
                    console.log(result);
                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;

                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }

            $scope.quer = function () {
              $scope.searchParams.startTime=$("#startTime").val();
              $scope.searchParams.endTime=$("#endTime").val();
              $scope.searchParams.sortType=$scope.param.sortType;
              if($scope.param.time!=""&&$scope.param.time!=null && ($scope.searchParams.startTime=="" || $scope.searchParams.startTime== null)){
                $scope.search();
              }else {
                if( $scope.searchParams.startTime=="" || $scope.searchParams.startTime== null){
                  $scope.alertModal({'content': '请选择开始时间'});
                  return;
              }
               if( $scope.searchParams.startTime > $scope.searchParams.endTime){
                  $scope.alertModal({'content': '开始时间不能大于结束时间'});
                  return;
              }
              $scope.searchRe();
              }

            }
            $scope.searchRe = function () {

                $scope.loading = true;

                $.ajax({
                    url : $scope.app.project_name+'/forumAttentionPerson/read/list',
                    data: $scope.searchParams
                }).then(function(result) {

                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;

                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }
            $scope.select = function () {
             $scope.searchParams.pageNum =1 ;
             $scope.quer();
            }

            $scope.selectbyTime = function () {
             $scope.param.pageNum=1;
             $scope.search();
            }

            $scope.isSelected = function (id) {
                return $scope.selected.indexOf(id) >= 0;
            };


            $scope.search();

            $scope.clearSearch = function() {
                $scope.searchParams = {};
                $scope.param={};
                $scope.search();
                $(".editSortBtn").show();
                $(".saveSortBtn").hide();
            }



            // 翻页
            $scope.pagination = function (pageNo) {
                $scope.param.pageNum=pageNo;
                $scope.searchParams.pageNum=pageNo;
                if($scope.searchParams.startTime=="" || $scope.searchParams.startTime== null){
                    $scope.search();
                }else{
                    $scope.quer();
                }
            };


            $scope.businessLicenses = [];
            $scope.preview = function(businessLicense){
                if (businessLicense != null && businessLicense != '') {
                    $scope.businessLicenses = businessLicense.split('|');
                }
                $scope.firstApply = true;
            }

        } ]);